import 'package:flutter/material.dart';

import '../const.dart';
import 'login.dart';
import 'register.dart';

class LoginMain extends StatefulWidget {
  @override
  _LoginMainState createState() => _LoginMainState();
}

class _LoginMainState extends State<LoginMain> with WidgetsBindingObserver {
  var _currentPage = 0;
  var _color0 = Colors.transparent,
      _color1 = gold,
      _color0Text = gold,
      _color1Text = Colors.white;
  var _controller = PageController(
    initialPage: 0,
  );

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
//    print("lifeChanged $state");
  }

  @override
  void dispose() {
    super.dispose();
    WidgetsBinding.instance.removeObserver(this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          backgroundColor: black,
          actions: <Widget>[
            SizedBox(
              width: 60,
            ),
          ],
          title: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              MaterialButton(
                onPressed: () {
                  _controller.jumpToPage(0);
                  setState(() {
                    _color0 = Colors.transparent;
                    _color1 = gold;
                    _color0Text = gold;
                    _color1Text = Colors.white;
                  });
                },
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(30))),
                height: 30,
                minWidth: 90,
                elevation: 0,
                color: _color0,
                child: Text('登录',
                    style: TextStyle(color: _color0Text, fontSize: 16)),
              ),
              SizedBox(
                width: 16,
              ),
              MaterialButton(
                onPressed: () {
                  _controller.jumpToPage(1);
                  setState(() {
                    _color1 = Colors.transparent;
                    _color0 = gold;
                    _color1Text = gold;
                    _color0Text = Colors.white;
                  });
                },
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(30))),
                height: 30,
                minWidth: 90,
                elevation: 0,
                color: _color1,
                child: Text('注册',
                    style: TextStyle(color: _color1Text, fontSize: 16)),
              ),
            ],
          )),
      body: Container(
        color: black,
        child: PageView(
          controller: _controller,
          children: [Login(), Register()],
          physics: NeverScrollableScrollPhysics(),
        ),
      ),
    );
  }
}
